package com.visizen.wisdomclass.server.client;

import com.visizen.wisdomclass.server.model.WcOrganizationUser;
import com.visizen.wisdomclass.server.model.WcOrganizationUserExample;
import com.visizen.wisdomclass.server.model.WcUser;
import com.visizen.wisdomclass.server.model.dto.OrganizationExt;
import com.visizen.wisdomclass.server.model.dto.OrganizationUserExt;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface WcOrganizationUserMapper {
    /**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization_user
	 * @mbggenerated
	 */
	@SelectProvider(type = WcOrganizationUserSqlProvider.class, method = "countByExample")
	int countByExample(WcOrganizationUserExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization_user
	 * @mbggenerated
	 */
	@DeleteProvider(type = WcOrganizationUserSqlProvider.class, method = "deleteByExample")
	int deleteByExample(WcOrganizationUserExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization_user
	 * @mbggenerated
	 */
	@Delete({ "delete from wc_organization_user",
			"where id = #{id,jdbcType=BIGINT}" })
	int deleteByPrimaryKey(Long id);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization_user
	 * @mbggenerated
	 */
	@Insert({
			"insert into wc_organization_user (id, organization_id, ",
			"user_id, role_id)",
			"values (#{id,jdbcType=BIGINT}, #{organization_id,jdbcType=BIGINT}, ",
			"#{user_id,jdbcType=BIGINT}, #{role_id,jdbcType=BIGINT})" })
	int insert(WcOrganizationUser record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization_user
	 * @mbggenerated
	 */
	@InsertProvider(type = WcOrganizationUserSqlProvider.class, method = "insertSelective")
	int insertSelective(WcOrganizationUser record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization_user
	 * @mbggenerated
	 */
	@SelectProvider(type = WcOrganizationUserSqlProvider.class, method = "selectByExample")
	@Results({
			@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
			@Result(column = "organization_id", property = "organization_id", jdbcType = JdbcType.BIGINT),
			@Result(column = "user_id", property = "user_id", jdbcType = JdbcType.BIGINT),
			@Result(column = "role_id", property = "role_id", jdbcType = JdbcType.BIGINT) })
	List<WcOrganizationUser> selectByExample(WcOrganizationUserExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization_user
	 * @mbggenerated
	 */
	@Select({ "select", "id, organization_id, user_id, role_id",
			"from wc_organization_user", "where id = #{id,jdbcType=BIGINT}" })
	@Results({
			@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
			@Result(column = "organization_id", property = "organization_id", jdbcType = JdbcType.BIGINT),
			@Result(column = "user_id", property = "user_id", jdbcType = JdbcType.BIGINT),
			@Result(column = "role_id", property = "role_id", jdbcType = JdbcType.BIGINT) })
	WcOrganizationUser selectByPrimaryKey(Long id);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization_user
	 * @mbggenerated
	 */
	@UpdateProvider(type = WcOrganizationUserSqlProvider.class, method = "updateByExampleSelective")
	int updateByExampleSelective(@Param("record") WcOrganizationUser record,
			@Param("example") WcOrganizationUserExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization_user
	 * @mbggenerated
	 */
	@UpdateProvider(type = WcOrganizationUserSqlProvider.class, method = "updateByExample")
	int updateByExample(@Param("record") WcOrganizationUser record,
			@Param("example") WcOrganizationUserExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization_user
	 * @mbggenerated
	 */
	@UpdateProvider(type = WcOrganizationUserSqlProvider.class, method = "updateByPrimaryKeySelective")
	int updateByPrimaryKeySelective(WcOrganizationUser record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization_user
	 * @mbggenerated
	 */
	@Update({ "update wc_organization_user",
			"set organization_id = #{organization_id,jdbcType=BIGINT},",
			"user_id = #{user_id,jdbcType=BIGINT},",
			"role_id = #{role_id,jdbcType=BIGINT}",
			"where id = #{id,jdbcType=BIGINT}" })
	int updateByPrimaryKey(WcOrganizationUser record);

	@Select("select * from wc_user where user_id in (select user_id " +
            " from wc_organization_user where organization_id=#{classId}) order by CONVERT(fullname USING gbk) asc")
    List<WcUser> selectUsersByClassId(@Param("classId") Long classId);

    //select organization by organizationId and userId
    @Select("SELECT * FROM wc_organization_user WHERE user_id=#{userId} and organization_id=#{oId}")
    OrganizationUserExt getOrganizationByOrgIdUserId(@Param("oId") long organizationId, @Param("userId") long userId);

    //通过userId获取用户的所有班级的详细信息?
    @Select("SELECT * FROM wc_organization_user WHERE user_id=#{userId} limit #{start},#{end}")
    @Results({
            @Result(property = "organization", column = "organization_id", one = @One(select = "getClassInfoByClassId"))
    })
    List<OrganizationUserExt> getOrganizationListByUserId(@Param("userId") long userId,
                                                          @Param("start") int start,
                                                          @Param("end") int end);

    //通过班级id查询班级的信息，包括查找出班级的年级
    @Select("SELECT * FROM wc_organization WHERE organization_id=#{classId} and category_id=3")
    @Results({
            @Result(property = "parent", column = "parent_organization_id", one = @One(select = "getGradeInfoByGradeId"))
    })
    OrganizationExt getClassInfoByClassId(@Param("classId") long classId);

    //通过年级ID查询出年级的信息，包括查找出班级的学?
    @Select("SELECT * FROM wc_organization WHERE organization_id=#{gradeId} and category_id=2")
    @Results({
            @Result(property = "parent", column = "parent_organization_id", one = @One(select = "getSchoolInfoBySchoolId"))
    })
    OrganizationExt getGradeInfoByGradeId(@Param("gradeId") long gradeId);

    //通过学校ID查询学校的信?
    @Select("SELECT * FROM wc_organization WHERE organization_id=#{schoolId}")
    OrganizationExt getSchoolInfoBySchoolId(@Param("schoolId") long schoolId);
}